package graph_viewer.factory;

import java.io.File;
import java.io.IOException;

import graph_viewer.structure.*;
import graph_viewer.structure.builder.*;
import graph_viewer.app_exception.*;
import graph_viewer.util.*;


public class  Graph_Builder_Factory{
	public static void main( String[] args ) throws IOException{
		Graph_Builder_Factory	gbf	= new Graph_Builder_Factory();
		
		String file_name	= args[0];

		String file_type	= File_Util.get_file_type( file_name );

		Debug.println( "file_type is " + file_type, 2 );
		Debug.println( "is TOMS file " + gbf.is_Toms_File( file_type ), 2 );
		
		
		Graph_Builder				gb		= gbf.create( file_name );
		/**/
	}
	
	public Graph_Builder_Factory(){
	}

	public Graph_Builder create( String data_file_name ) throws IOException{
		Graph_Builder	gb = null;

		Debug.println( "Create graph_builder from: " + data_file_name,  4 );
		if ( is_App_File(data_file_name) ){			
			gb = new App_Format_Graph_Builder( data_file_name );
		}else if ( is_Toms_File( data_file_name ) ){			
			gb = new TomS_Graph_Builder( data_file_name );
			//Debug.println( "TomS_Graph_Builder is created" + gb, 2 );		
		}else if ( is_Tabf_File(data_file_name) ){
			gb = new Tab_Format_Graph_Builder( data_file_name );
			//Debug.println( "Tab_Format_Graph_Builder is created" + gb, 2 );
		}else if ( is_Spr_File(data_file_name) ){
			gb = new Spring_Graph_Builder( data_file_name );
			//Debug.println( "Spring_Graph_Builder is created" + gb, 2 );
		}else if ( is_Clustered_File( data_file_name ) ){
			//Debug.println( "Clustered_Graph_Builder is created" + gb, 2 );
			gb = new Clustered_Graph_Builder( data_file_name );
		}else if ( is_Dat_File(data_file_name) ){
			Debug.println( "is_Dat_File", 4 );
			gb = new Dat_Graph_Builder( data_file_name );
			
			Debug.println( "Dat_Graph_Builder is created: " + gb, 4 );
		}else {
			throw new App_Exception( "Invalid File Type to Create Graph Builder!\n" );
		}
		
		return gb;
	}


	private boolean is_file_type( String data_file_name, String specfied_type ){
		
		String file_type	= File_Util.get_file_type( data_file_name );
		
		return file_type.equals( specfied_type );
	}

	public boolean is_Dat_File( String data_file_name ){		
		return is_file_type( data_file_name, Factory_Values.BUILDER_TYPE_DAT );
	}
	
	public boolean is_App_File( String data_file_name ){
		return is_file_type( data_file_name, Factory_Values.BUILDER_TYPE_APP );
	}

	public boolean is_Toms_File( String data_file_name ){
		return is_file_type( data_file_name, Factory_Values.BUILDER_TYPE_TOMS );
	}

	public boolean is_Tabf_File( String data_file_name ){
		return is_file_type( data_file_name, Factory_Values.BUILDER_TYPE_TABF );
	}

	public boolean is_Spr_File( String data_file_name ){
		return is_file_type( data_file_name, Factory_Values.BUILDER_TYPE_SPR );
	}

	public boolean is_Clustered_File( String data_file_name ){		
		return is_file_type( data_file_name, Factory_Values.BUILDER_TYPE_CLU ); 
	}
}